<?php
    class HelperBGtop{
    function getAllAct($cid){
       $qr = "SELECT ACTT_DATE,ACTT_PERIOD_START,ACTT_NAME,OCBA_NAME,ACTT_USER_CREATE,ACTT_CODE
                    FROM actt
                    LEFT JOIN ocba ON actt.ACTT_OCBA_CODE = ocba.OCBA_CODE
                    WHERE ACTT_WEBF=1
                    ORDER BY ACTT_CODE DESC
                    LIMIT 0,3
              ";         
        //load data
      // echo $qr;
       $db = JFactory::getDbo();
       $db->setQuery($qr);
       $result = $db->loadObjectList();
       return $result;
	}
    
    function getNameOcba($cid){
       $qr = "SELECT OCBA_NAME
        FROM kc2vr_users INNER JOIN ocba ON kc2vr_users.USEM_OCBA_CODE=ocba.OCBA_CODE
        WHERE kc2vr_users.id=$cid
              ";         
        //load data
      // echo $qr;
       $db = JFactory::getDbo();
       $db->setQuery($qr);
       $result = $db->loadResult();
       return $result;
	}
    
    function getLink(){
       $qr = "SELECT * from link";   
       $db = JFactory::getDbo();
       $db->setQuery($qr);
       $result = $db->loadObjectList();
       return $result;
	}
    function getAllDownd($cid){
       $qr = "SELECT DOWI_CODE,DOWI_NAME,DOWI_DATE,DOWI_PATH,DOWI_DESCRIPTION
                    FROM dowi
                    ORDER BY DOWI_CODE DESC
                    LIMIT 0,3
              ";         
        //load data
      // echo $qr;
       $db = JFactory::getDbo();
       $db->setQuery($qr);
       $result = $db->loadObjectList();
       return $result;
	}
    
     /**
     * get dowi path from dowi_code
    **/
    function getDowiPath($cid){
        $qr = "SELECT DOWI_PATH
                        FROM dowi
                        WHERE DOWI_CODE = '$cid'";
       
       // load data
        $db = JFactory::getDbo();
       $db->setQuery($qr);
       $result = $db->loadObject();
       return $result->DOWI_PATH;;
    }  
 
    
    function getAllInfo($cid){
        
       //$qr = "SELECT distinct CAIN_CODE,CAIN_NAME,USIN_USER_CODE
//                  FROM cain INNER JOIN info ON cain.CAIN_CODE=info.INFO_CAIN_CODE
//                		INNER JOIN usin ON info.INFO_CODE=usin.USIN_INFO_CODE
//                  WHERE USIN_USER_CODE=$cid
//                        ORDER BY CAIN_CODE DESC
//                        LIMIT 0,4
//              ";  
        $qr = "SELECT distinct CAIN_CODE,CAIN_NAME,USIN_USER_CODE
                          FROM cain INNER JOIN info ON cain.CAIN_CODE=info.INFO_CAIN_CODE
                        		INNER JOIN usin ON info.INFO_CODE=usin.USIN_INFO_CODE
                          WHERE USIN_USER_CODE=$cid AND info.INFO_FLAG=1
                                ORDER BY CAIN_CODE DESC
                                LIMIT 0,4
                      ";         
        //load data
       $db = JFactory::getDbo();
       $db->setQuery($qr);
       $result = $db->loadObjectList();
                 //load data info
                foreach($result as $row)
                    {
                        $a= $row->CAIN_CODE;
                        $qr = "SELECT USIN_USER_CODE,CAIN_NAME,CAIN_CODE,INFO_DATE,INFO_TITLE,INFO_CODE
                                FROM cain INNER JOIN info ON cain.CAIN_CODE=info.INFO_CAIN_CODE
                                		INNER JOIN usin ON info.INFO_CODE=usin.USIN_INFO_CODE 
                                        WHERE INFO_CAIN_CODE=($a) AND USIN_USER_CODE=$cid AND info.INFO_FLAG=1 ORDER BY INFO_CODE DESC LIMIT 0,3";  
                           // echo $qr;
                            $db->setQuery($qr);
                            $data = $db->loadObjectList();
                            $row->data = $data;
                         
                    }
                
                    return $result;
	}
    
     /**
     * get all image  from master banner
    **/
    function getAllImgFromMaster(){
        $qr = "SELECT * FROM banner";
       
       // load data
        $db = JFactory::getDbo();
       $db->setQuery($qr);
       $result = $db->loadObjectList();
       return $result;
    } 

    public function newline2br($str){
        $str = str_replace("\r\n", "\n", $str); 
        $str = str_replace("\n", "<br>", $str); 
        return $str;
    }
        
        
}

?>